//
//  NSObject+ToJson.m
//  Courses
//
//  Created by xxx on 15/1/6.
//  Copyright (c) 2015年 wtf. All rights reserved.
//

#import "NSObject+ToJson.h"

@implementation NSObject (ToJson)

-(NSString*) JSONStringWithOption:(int) option
{
    if(self == nil){
        return nil;
    }
    NSError *err = nil;
    NSData *data = [NSJSONSerialization dataWithJSONObject:self
                                                   options:option
                                                     error:&err];
    
    if(err)
        NSLog(@"%@", [err description]);
    
    return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    
}

- (NSString *)prettyJSONString {
    return [self JSONStringWithOption:NSJSONWritingPrettyPrinted];
}

- (NSString *)JSONStringRepresentation {
    return [self JSONStringWithOption:0];
}

@end
